#include "gtlCore.h"

namespace GTL
{
	namespace Engine
	{
		namespace Logging
		{
#ifdef GTL_DEBUG
			int LogTypes = Info | Warning | Error | Resource;
#else
			int LogTypes = Error;
#endif
		}

		///************************************************************************/
		///* Graphics                                                             */
		///************************************************************************/

		FontRef::~FontRef()
		{
			Backend->DestroyFont(this);
		}

		ImageRef::~ImageRef()
		{
			Backend->DestroyImage(this);
		}

		ShaderRef::~ShaderRef()
		{
			Backend->DestroyShader(this);
		}

		///************************************************************************/
		///* Core                                                                 */
		///************************************************************************/

		
	}

	using Structures::DataNode;
	template <>
	bool NodeToObject(Engine::ColorRGBA& obj, const DataNode* node)
		//ColorRGBA::ColorRGBA(DataNode* node) : R(1), G(1), B(1), A(1)
	{
		if (!node) return false;

		obj.R = obj.G = obj.B = obj.A = 1.0f;

		if (node->Type == DataNode::LIST)
		{
			int c = 0;
			for (DataNode::ListType::const_iterator i=node->List.begin(); i!=node->List.end(); ++i)
			{
				switch (c)
				{
				case 0: obj.R = (float)((*i)->Number); break;
				case 1: obj.G = (float)((*i)->Number); break;
				case 2: obj.B = (float)((*i)->Number); break;
				case 3: obj.A = (float)((*i)->Number); break;
				}
				c++;
			}
		} else if (node->Type == DataNode::DICT)
		{

		} else if (node->Type == DataNode::NUMBER)
		{
			uint32_t num = (uint32_t)node->Number;
			obj.A = float(num&255)/255.0f;
			obj.B = float((num>>8)&255)/255.0f;
			obj.G = float((num>>16)&255)/255.0f;
			obj.R = float((num>>24)&255)/255.0f;
		} else if (node->Type == DataNode::STRING)
		{
			if (node->String == "black")
				obj.R = obj.G = obj.B = 0.0f;
			else if (node->String == "red")
			{
				obj.G = obj.B = 0.0f;
			} else if (node->String == "green")
			{
				obj.R = obj.B = 0.0f;
			} else if (node->String == "blue")
			{
				obj.R = obj.G = 0.0f;
			} else if (node->String == "cyan")
			{
				obj.R = 0.0f;
			} else if (node->String == "magenta")
			{
				obj.G = 0.0f;
			} else if (node->String == "yellow")
			{
				obj.B = 0.0f;
			} else if (node->String == "white")
			{
			}
		}
		return true;
	}
}